#version 450

layout(location = 0) out vec2 vUV;

// Push constants for view transform (zoom and pan)
layout(push_constant) uniform Params {
    float winCenter;  // not used in vertex
    float winWidth;   // not used in vertex
    int   invert;     // not used in vertex
    float zoom;       // > 0
    float offsetX;    // pan in UV space
    float offsetY;    // pan in UV space
} params;

void main() {
    // Fullscreen triangle (3 vertices, using gl_VertexIndex)
    const vec2 pos[3] = vec2[](
        vec2(-1.0, -1.0),
        vec2( 3.0, -1.0),
        vec2(-1.0,  3.0)
    );
    vec2 p = pos[gl_VertexIndex];
    vec2 baseUV = p * 0.5 + 0.5; // map from NDC to [0,1]
    float z = max(params.zoom, 1e-6);
    vec2 center = vec2(0.5) + vec2(params.offsetX, params.offsetY);
    vUV = (baseUV - center) / z + center; // zoom and pan around center
    gl_Position = vec4(p, 0.0, 1.0);
}